﻿//测试事件发布和处理

using Microsoft.Extensions.DependencyInjection;
using PoemGame.Domain.GameAggregate;
using PoemGame.Domain.PlayerAggregate;
using PoemGame.Events.MediatR.Console;
using PoemGame.Events.Shared;

//创建一个游戏
var game = new Game(Guid.NewGuid(), 
    new GameType("Feihualing", ""), 
    PlayType.Inturn, "测试", 
    "花");
//创建一个玩家
var player = new Player(Guid.NewGuid(), 
    "zhangsan", 
    "zhangsn", 
    10);
//玩家加入游戏
game.PlayerJoinGame(player);
//获取发布事件的总线
var ms= Utility.GetServices().GetService<ILocalEventBus>();
//发布game中的事件
foreach (var d in game.GetLocalDomainEvents())
{
    await ms?.PublishAsync(d.EventData)!;
}

var outs= Utility.GetServices().GetService<IOutBoundEventBus>();

foreach (var d in game.GetOutBoundDomainEvents())
{
    await outs?.PublishAsync(d.EventData)!;
}